package com.summer.framework.core.context;

import com.alibaba.ttl.TransmittableThreadLocal;

/**
 * Description:
 * @auther Ice Yang
 * Date 2025/7/18 16:07
 */
public class UserContext {

    private static final ThreadLocal<String> USER_NAME = new TransmittableThreadLocal<>();

    private static final ThreadLocal<String> NAME = new TransmittableThreadLocal<>();

    private static final ThreadLocal<Long> USER_ID = new TransmittableThreadLocal<>();

    private static final ThreadLocal<Boolean> SUPER_ADMIN = new TransmittableThreadLocal<>();

    public static void setUserName(String userName) {
        USER_NAME.set(userName);
    }

    public static String getUserName() {
        return USER_NAME.get();
    }

    public static void setName(String name) {
        NAME.set(name);
    }

    public static String getName() {
        return NAME.get();
    }
    public static void setUserId(Long userId) {
        USER_ID.set(userId);
    }

    public static Long getUserId() {
        return USER_ID.get();
    }

    public static void setSuperAdmin(Boolean superAdmin) {
        SUPER_ADMIN.set(superAdmin);
    }

    public static Boolean isSuperAdmin() {
        return SUPER_ADMIN.get() != null && SUPER_ADMIN.get();
    }

    public static void clear() {
        USER_NAME.remove();
        USER_ID.remove();
        SUPER_ADMIN.remove();
    }
}
